<?php

class Application_Model_Sku extends Application_Model_DomainObject {
    
    protected $_id;
    
    protected $_price;
    
    protected $_dateCreated;
    
    protected $_quantity;
    
    protected $_properties;
    
    protected $_productId;
    
    protected $_skuNo;

        /**
     * 返回对应的数据库操作类
     * @return \Application_Model_DbTable_Sku 
     */
    private static function getDb(){
        return new Application_Model_DbTable_Sku();
    }

    /**
     * 根据产品ID返回该产品的所有SKU
     * @param type $productId
     * @return array 
     */
    public static function getByProductId($productId){
        return Application_Model_Sku::getDb()->queryAll(array('productId'=>$productId));
    }
    
    public static function getBySkuNo($sku){
        return Application_Model_Sku::getDb()->queryOne(array('skuNo'=>$sku));
    }

    /**
     * 返回SKU的文字说明
     * @return string
     */
    public function getTitle(){
        $ps= split(';', $this->_properties);
        $title =array();
        foreach ($ps as $p){
            $values= split(':', $p);
            $title[]=$values[2].':'.$values[3];
        }
        return $title;
    }
}